﻿using AskPro.Models.DataContext;
using AskPro.Models.Wrappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AskPro.Models.Repositories
{
    public class QuestionRepository : RepositoryBase
    {
        public int pageSize = 20;

        public IEnumerable<QuestionW> GetQuestions(int page)
        {
            var db = AskContext.Create();
            Guid userId = GetUserId();

            var questions = db.Questions.Where(q => q.UserId != userId)
                                .OrderByDescending(q => q.DateCreated)
                                .Skip(pageSize * (page - 1))
                                .Take(pageSize)
                                .ToList() //need to enumerate the query because it gives an error that sql doenst know how to translate the select
                                .Select(q => new QuestionW(q));

            return questions;
        }
       
    }
}